<script lang="ts" setup>
import { TOKEN_DEL_KEY } from '@/utils/tokenConfig'
import { useShopInfoStore } from '@/store/modules/shopInfo'
import { doPostLogout } from '@/apis/sign'
import { queryConfigByModule } from '@/apis/order'
import { useAmapKeyStore } from '@/store/modules/amapKey'
import store from './store/global'
import { watch } from 'vue'
import { getLocation, locToAddress } from './apis/amap'

const amapKeyStore = useAmapKeyStore(store)
watch(
    () => amapKeyStore,
    async (val) => {
        if (val.getAmapWebServiceKey) {
            const lb = await getLocation()
            locToAddress([lb.longitude, lb.latitude])
        }
    },
    {
        deep: true,
    },
)
// #ifdef H5
const getConfigByModule = async () => {
    const { code, data } = await queryConfigByModule('OTHERS_SETTING, PUBLIC_SETTING')
    if (code === 200 && data) {
        uni.$on('updateTitle', () => {
            uni.setNavigationBarTitle({
                title: data.SHOP_MOBILE_NAME, // 设置为你想要显示的标题文本
            })
        })
        document.getElementById('website_icon')?.setAttribute('href', data.WEB_SIT_ICON)
    }
}
getConfigByModule()
// #endif
/**
 * token过期监听
 */
uni.$on(TOKEN_DEL_KEY, () => {
    const $store = useShopInfoStore()
    doPostLogout()
    $store.DEL_SHOP_INFO()
    // 回到登录页
    uni.reLaunch({
        url: '/pages/sign/index',
    })
})
</script>

<style lang="scss">
@import './uni_modules/vk-uview-ui/index.scss';
page {
    background-color: #f5f5f5;
    user-select: none;
}
</style>
